getApp();
var t = getApp().constants,
  e = (getApp().constants.util, null),
  a = null,
  o = null,
  i = null,
  n = [],
  c = null,
  u = t.qqMapKey;
JSON.stringify({
  latitude: "",
  longitude: ""
});
Page(t.pageCheck({
  data: {
    canIUseGetUserProfile: t.canIUseGetUserProfile,
    isWxUserAuth: "0",
    houseList: [],
    otherList: [],
    commentList: [],
    starYellow: "/images/icon_star_yellow.png",
    starGray: "/images/icon_star_gray.png",
    isInsider: 2,
    isShowCodeDialog: !1,
    isCustomerDialog: !1,
    city: "获取中",
    isLocation: !1,
    isRefuseLocation: !1,
    fromAddressChoose: 0,
    groupList: [],
    active: 0,
    tabIndex: 0,
    sevIndex: 1,
    sevList: [{
      id: 0,
      title: "服务一对一",
      text: "配对专属一对一客服管家，提供终身房屋咨询",
      url: "https://qiniu.daxiangyanfang.com/wapp/housesev_ban01.jpg"
    }, {
      id: 1,
      title: "专业人员",
      text: "均通过大象统一系统培训，具备职业技能认证",
      url: "https://qiniu.daxiangyanfang.com/wapp/housesev_ban02.jpeg"
    }, {
      id: 2,
      title: "标准作业",
      text: "全程线上标准化作业流程，9类35目273",
      url: "https://qiniu.daxiangyanfang.com/wapp/housesev_ban03.png"
    }, {
      id: 3,
      title: "认定资质",
      text: "浙江省房产协会合作单位，共同拟定行业执行",
      url: "https://qiniu.daxiangyanfang.com/wapp/housesev_ban04.jpg"
    }, {
      id: 4,
      title: "经验丰富",
      text: "成立5年服务5万业主，覆盖600余个小区",
      url: "https://qiniu.daxiangyanfang.com/wapp/housesev_ban05.png"
    }],
    isDelay200: !1,
    isDelay1000: !1
  },
  onReady: function () {},
  onShow: function () {
    e = this, a = wx.getStorageSync("elephant_token"), o = wx.getStorageSync("locAuth"), setTimeout((function () {
      e.setData({
        isDelay200: !0
      })
    }), 100), setTimeout((function () {
      e.setData({
        isDelay1000: !0
      }), e.getMonitorOrder()
    }), 200), e.getBanner(), e.httpGetList(), [], e.getCommentList(), a.userId && (e.setData({
      isWxUserAuth: a.authResult
    }), e.httpGetRole()), o ? (o.isLocation && (e.data.isLocation = o.isLocation, e.data.city = o.city), o.isRefuseLocation && (e.data.isRefuseLocation = o.isRefuseLocation)) : e.checkLocationAuth(), e.setData({
      isLocation: e.data.isLocation,
      isRefuseLocation: e.data.isRefuseLocation,
      city: e.data.city
    });
    var t = s.getLocation();
    console.log(t, "地图选点返回"), t ? (e.setData({
      city: t.city ? t.city : t.name
    }), o ? o.city = t.city ? t.city : t.name : o = {
      city: t.city ? t.city : t.name
    }, wx.setStorageSync("locAuth", o), t.city && e.httpGroupList()) : null === t && e.checkLocationAuth(), wx.removeStorageSync("productInfo"), wx.removeStorageSync("addressEditInfo"), wx.removeStorageSync("editForm"), wx.removeStorageSync("userStat"), wx.removeStorageSync("fatherOrderId")
  },
  onLoad: function () {
    e = this, wx.showShareMenu()
  },
  onHide: function () {
    clearTimeout(i), clearTimeout(c)
  },
  onUnload: function () {
    clearTimeout(i), clearTimeout(c)
  },
  onPullDownRefresh: function (t) {},
  onReachBottom: function (t) {},
  onPageScroll: function (t) {},
  onShareAppMessage: function () {
    return {
      title: "大象到家，房屋无忧",
      imageUrl: "https://qiniu.daxiangyanfang.com/wapp/home_share_new.jpg?time=" + (new Date).getTime(),
      path: "pages/ui/index/index",
      success: function (t) {}
    }
  },
  clickSpell: function (t) {
    if (1 == e.data.isWxUserAuth) {
      var a = t.currentTarget.dataset,
        o = "?inviteId=" + a.inviteid + "&productType=" + a.prdtype + "&productId=" + a.productid + "&buyType=" + a.buytype + "&isShare=true&fromDetail=true";
      wx.navigateTo({
        url: "/packageA/ui/shareInvite/shareInvite" + o
      })
    }
  },
  clickPreview: function (t) {
    var e = t.currentTarget.dataset;
    wx.previewImage({
      current: e.curImg,
      urls: e.list
    })
  },
  chooseTab: function (t) {
    var a = t.currentTarget.dataset.index;
    e.setData({
      tabIndex: a
    })
  },
  goDetail: function (t) {
    var e = t.currentTarget.dataset,
      a = "";
    3 == e.type ? (4 == e.id && (a = "houseGold/houseGold"), 1 == e.id && (a = "houseHigh/houseHigh"), 3 == e.id && (a = "houseBlank/houseBlank"), 2 == e.id && (a = "houseRecheck/houseRecheck"), 5 == e.id && (a = "houseTest/houseTest")) : 4 == e.type && (3 == e.id && (a = "airAll/airAll"), 2 == e.id && (a = "airJia/airJia")), wx.navigateTo({
      url: "".concat("../../../packageA/ui/").concat(a, "?type=").concat(e.type, "&id=").concat(e.id, "&maxprice=").concat(e.maxprice, "&minprice=").concat(e.minprice, "&name=").concat(e.name)
    })
  },
  goOther: function (t) {
    var e = t.currentTarget.dataset,
      a = "";
    a = 11 == e.type ? "sign/sign" : "supervision/supervision", wx.navigateTo({
      url: "".concat("../../../packageA/ui/").concat(a, "?type=").concat(e.type, "&id=").concat(e.id, "&maxprice=").concat(e.maxprice, "&minprice=").concat(e.minprice, "&name=").concat(e.name)
    })
  },
  goIndexDetail: function (t) {
    debugger
    var a = t.currentTarget.dataset;
    if (a.urls) {
      var o = a.urls.split(",");
      wx.setStorageSync("bannerUrls", JSON.stringify(o)), wx.navigateTo({
        url: "../../../packageB/ui/bannersDetail/bannersDetail?id=".concat(a.id, "&title=").concat(a.title)
      })
    }
    "1" == a.id && wx.navigateTo({
      url: "/packageC/ui/activityFree/activityFree"
    }), e.bannerCount(a.id)
  },
  goGroupList: function () {
    wx.navigateTo({
      url: "/packageB/ui/groupList/groupList?city=" + e.data.city
    })
  },
  goProducts: function () {
    wx.navigateTo({
      url: "/packageB/ui/products/products"
    })
  },
  goCommentList: function () {
    wx.navigateTo({
      url: "/packageB/ui/commentList/commentList"
    })
  },
  goPartner: function () {
    wx.navigateTo({
      url: "/packageC/ui/partner/partner"
    })
  },
  toggleCode: function () {
    e.data.isShowCodeDialog = !e.data.isShowCodeDialog, e.setData({
      isShowCodeDialog: e.data.isShowCodeDialog
    })
  },
  toggleCustomer: function () {
    e.data.isCustomerDialog = !e.data.isCustomerDialog, e.setData({
      isCustomerDialog: e.data.isCustomerDialog
    })
  },
  clickPhone: function (t) {
    var e = t.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: e
    }).catch((function (t) {}))
  },
  sevSlideChange: function (t) {
    var a = t.detail.current + 1;
    t.detail.source;
    e.setData({
      sevIndex: a
    })
  },
  getBanner: function () {
    t.http.httpPost({
      url: "client_banners/activity_banner",
      data: {
        type: 1
      },
      complete: function (t) {},
      success: function (t) {
        e.setData({
          bannerList: t.data.clientBanners
        })
      },
      fail: function (t) {
        console.log(t, "-fail-")
      }
    })
  },
  httpGetList: function () {
    t.http.httpGet({
      url: "index/product_up",
      data: {},
      complete: function (t) {},
      success: function (t) {
        wx.hideLoading();
        var a = [];
        a.push(t.data[1].categoryList[0]), a.push(t.data[3].categoryList[0]), e.setData({
          houseList: t.data[0].categoryList.slice(0, 3),
          otherList: a
        })
      },
      fail: function (t) {}
    })
  },
  getCommentList: function () {
    t.http.httpGet({
      url: "feedback/user_moment",
      data: {
        pageNo: 1,
        pageSize: 3,
        isMarvellous: 1
      },
      complete: function (t) {},
      success: function (t) {
        var a = t.data.feedbackLogVMList;
        a.forEach((function (t, e) {
          t.label && (t.labels = t.label.split(","))
        })), e.setData({
          commentList: a
        })
      },
      fail: function (t) {}
    })
  },
  getMonitorOrder: function () {
    t.http.httpPost({
      url: "index/data_count",
      data: {},
      success: function (t) {
        e.setData({
          countData: t.data
        }), i = setTimeout(e.getMonitorOrder, 6e5)
      }
    })
  },
  bannerCount: function (a) {
    t.http.httpPost({
      url: "client_banners/statistics_banner",
      data: {
        city: "获取中" == e.data.city ? "" : e.data.city,
        id: a
      },
      success: function (t) {}
    })
  },
  httpGetRole: function () {
    t.http.httpGet({
      url: "channelOrder/characterAffirm",
      data: {
        userId: a.userId
      },
      complete: function (t) {},
      success: function (t) {
        e.setData({
          isRole: t.data.inviteCharacter
        })
      },
      fail: function (t) {}
    })
  },
  httpGroupList: function () {
    wx.removeStorageSync("groupDataObj"), t.http.httpPost({
      url: "user_invite/artificial_group_list",
      data: {
        city: e.data.city,
        pageNo: 1,
        pageSize: 10,
        productType: "",
        productId: ""
      },
      complete: function (t) {},
      success: function (t) {
        if (t.data && t.data.groupList && t.data.groupList.length) {
          for (var a = t.data.groupList.slice(0, 4), o = [], i = 0; i < a.length; i++) {
            a[i].inviteImage && a[i].inviteImage.length > 5 && (a[i].inviteImage = a[i].inviteImage.slice(0, 5));
            var c = a[i].endDate ? a[i].endDate : a[i].inviteDate;
            o.push(c), a[i].len = a[i].groupPeopleCount - a[i].groupCount
          }
          n = o, e.setData({
            groupList: a,
            groupTotal: t.data.total
          }), e.countDownIndex();
          for (var s = [], u = t.data.groupList, r = 0; r < u.length; r++) {
            u[r].inviteImage && u[r].inviteImage.length > 5 && (u[r].inviteImage = u[r].inviteImage.slice(0, 5));
            var l = u[r].endDate ? u[r].endDate : u[r].inviteDate;
            s.push(l), u[r].len = u[r].groupPeopleCount - u[r].groupCount
          }
          var g = {
            list: u,
            times: s,
            totalPage: t.data.totalPage
          };
          wx.setStorageSync("groupDataObj", g)
        } else n = [], e.setData({
          groupList: []
        });
        console.log(e.data.groupList.length, "团数据", e.data.isLocation)
      },
      fail: function (t) {}
    })
  },
  timeFormat: function (t) {
    return t < 10 ? "0" + t : t
  },
  countDownIndex: function () {
    var t = this,
      a = (new Date).getTime(),
      o = [],
      i = e.data.groupList;
    n.forEach((function (e) {
      var i = new Date(e).getTime(),
        n = null;
      if (i - a > 0) {
        var c = (i - a) / 1e3,
          s = parseInt(c / 86400),
          u = parseInt(c % 86400 / 3600),
          r = parseInt(c % 86400 % 3600 / 60),
          l = parseInt(c % 86400 % 3600 % 60);
        n = {
          day: t.timeFormat(s),
          hou: t.timeFormat(u),
          min: t.timeFormat(r),
          sec: t.timeFormat(l)
        }
      } else n = {
        day: "00",
        hou: "00",
        min: "00",
        sec: "00"
      };
      o.push(n)
    })), i.forEach((function (t, e) {
      o.forEach((function (a, o) {
        e == o && (t.countDownDate = a)
      }))
    })), e.setData({
      groupList: i
    }), c = setTimeout(e.countDownIndex, 1e3)
  },
  getUserProfile: function (t) {
    wx.getUserProfile({
      desc: "用于完善头像昵称显示",
      success: function (a) {
        console.log(a, "授权 首页 new"), wx.setStorageSync("wxUserInfo", a.userInfo);
        var o = a.rawData,
          i = a.signature,
          n = a.encryptedData,
          c = a.iv;
        wx.login({
          success: function (a) {
            console.log(a, "login"), a.code ? e.httpLogin(o, i, n, c, a.code, t) : e.getCodeError()
          },
          fail: function (t) {
            e.getCodeError(), console.log(a, "微信login失败 首页 new")
          }
        })
      },
      fail: function (t) {
        console.log(res, "授权失败 首页 new")
      }
    })
  },
  getCodeError: function () {
    wx.clearStorageSync("wxUserInfo"), wx.showToast({
      title: "微信授权失败，请重新点击"
    })
  },
  getWxUserInfo: function (t) {
    wx.login({
      success: function (a) {
        if (a.code) {
          var o = a.code;
          wx.getSetting({
            success: function (a) {
              a.authSetting["scope.userInfo"] && wx.getUserInfo({
                success: function (a) {
                  console.log(a, "授权 首页 old"), wx.setStorageSync("wxUserInfo", a.userInfo);
                  var i = a.rawData,
                    n = a.signature,
                    c = a.encryptedData,
                    s = a.iv;
                  e.httpLogin(i, n, c, s, o, t)
                },
                fail: function (t) {
                  console.log(t, "getUserInfo fail")
                }
              })
            },
            fail: function (t) {}
          })
        }
      }
    })
  },
  httpLogin: function (a, o, i, n, c, s) {
    var u = {
      rawData: a,
      signature: o,
      encryptedData: i,
      iv: n,
      code: c
    };
    t.http.httpLogin({
      url: "login/auth",
      data: JSON.parse(JSON.stringify(u)),
      complete: function () {},
      success: function (t) {
        console.log(t, "login 获取userid 首页"), wx.setStorageSync("elephant_token", t.data), e.setData({
          isWxUserAuth: t.data.authResult
        }), wx.showToast({
          title: "授权完成"
        }), e.clickSpell(s)
      },
      fail: function (t) {}
    })
  },
  checkLocationAuth: function () {
    wx.getSetting({
      success: function (t) {
        t.authSetting["scope.userLocation"];
        t.authSetting["scope.userLocation"] ? (console.log(t, "getSetting if"), e.startLocation()) : (console.log(t, "getSetting else"), e.authLocation())
      },
      fail: function (t) {
        e.authLocation()
      }
    })
  },
  startLocation: function () {
    wx.getLocation({
      type: "gcj02",
      isHighAccuracy: !0,
      complete: function (t) {},
      success: function (t) {
        console.log("startLocation", t.latitude), e.data.city = "获取中", e.setData({
          city: e.data.city
        }), e.parseLocation(t.latitude, t.longitude)
      },
      fail: function (t) {
        e.data.city = "点击重试", e.setData({
          city: e.data.city
        })
      }
    })
  },
  authLocation: function () {
    wx.authorize({
      scope: "scope.userLocation",
      success: function (t) {
        console.log("允许授权"), e.authSuccess()
      },
      fail: function (t) {
        console.log("拒绝授权"), o ? o.isRefuseLocation = !0 : o = {
          isRefuseLocation: !0
        }, wx.setStorageSync("locAuth", o), e.setData({
          isRefuseLocation: !0
        })
      }
    })
  },
  parseLocation: function (t, a) {
    var i = "https://apis.map.qq.com/ws/geocoder/v1/?location=".concat(t, ",").concat(a, "&key=PFGBZ-JGNK3-D4W3R-YY5OA-QS62Q-C5BKI");
    wx.request({
      url: i,
      data: {},
      header: {
        "Content-Type": "application/json"
      },
      success: function (t) {
        var a = t.data.result.ad_info.city;
        e.setData({
          city: a,
          isLocation: !0
        }), o ? (o.city = a, o.isLocation = !0) : o = {
          city: a,
          isLocation: !0
        }, wx.setStorageSync("locAuth", o), e.data.city && e.httpGroupList()
      },
      fail: function () {
        e.data.city = "定位失败", e.setData({
          city: e.data.city
        })
      }
    })
  },
  openSettingCallBack: function (t) {
    t.detail.authSetting["scope.userLocation"] && e.authSuccess()
  },
  authSuccess: function () {
    o ? (o.isLocation = !0, o.isRefuseLocation = !1) : o = {
      isLocation: !0,
      isRefuseLocation: !1
    }, wx.setStorageSync("locAuth", o), e.setData({
      isLocation: !0,
      isRefuseLocation: !1
    }), e.startLocation()
  },
  goAddressChoose: function () {
    wx.navigateTo({
      url: "plugin://chooseLocation/index?key=" + u + "&referer=腾讯位置服务地图选点&category=生活服务,小区"
    })
  }
}));